import { createRouter, createWebHistory } from 'vue-router';
import Layout from '@/views/Layout/index.vue';
import newRouter from './modules/new';
import postrRouter from './modules/post';
import serviceRouter from './modules/service';
import noticeRouter from './modules/notice';
import userRouter from './modules/user';

// 动态路由数组
export const asyncRoutes = [userRouter, newRouter, postrRouter, serviceRouter, noticeRouter];

// 固定路由
export const constantRoutes = [
  {
    path: '/',
    name: 'dashboard',
    redirect: '/dashboard',
    component: Layout,
    meta: {
      title: '数据看板',
      icon: 'FundViewOutlined',
      rank: 101,
      isTop: true,
    },
    children: [
      {
        path: '/', // 二级路由的地址
        component: () => import('@/views/dashboard/index.vue'),
        // 路由元信息
        meta: {
          title: '首页',
          icon: 'HomeOutlined',
          rank: 102,
        },
      },
    ],
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/Login/index.vue'),
    meta: { hidden: true, rank: 0 },
  },
  {
    path: '/detail/:id', // 路由地址
    name: 'detail',
    component: Layout,
    meta: { hidden: true, rank: 0 },
    children: [
      {
        path: '/detail/:id',
        name: 'detail',
        component: () => import('@/views/common/detail.vue'),
      },
    ],
  },
  {
    path: '/article', // 路由地址
    name: 'article',
    component: Layout,
    meta: { hidden: true, rank: 0 },
    children: [
      {
        path: '/article',
        name: 'article',
        component: () => import('@/views/common/article.vue'),
      },
    ],
  },
  {
    path: '/test',
    name: 'test',
    component: () => import('@/views/test/index.vue'),
    meta: { hidden: true, rank: 0 },
  },
];

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [...constantRoutes],
});

export default router;
